﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using UtilLib;
using UtilPublic.ServerLoger;
using System;
using UtilPublic.Serialization;
using System.Runtime.Serialization;
using System.Collections.Generic;

namespace ServerGame.GameObject
{
    // 时间组 关键字
    public enum EDataLoopDtKey
    {
        未知 = 0,
        日零点更新 = 1,
        日五点更新 = 2,
        日X点更新 = 3,
        周零点更新 = 11,//都按周日为最后一天来计算
        月零点更新 = 21,
        秒更新 = 31,
        十秒更新 = 32,
        一分钟更新 = 41,
        三分钟更新 = 42,
        五分钟更新 = 43,
        三十分钟更新 = 44,
        一小时更新 = 51,
    }
    /// <summary>
    /// 玩家心跳
    /// </summary>
    [DataContract]
    public class DataLoop
    {
        //时间
        [DataMember]
        public DateTime LoopDatetimeBase = DateTime.Now;
        //时间组
        [DataMember]
        public Dictionary<int, DateTime> DictLoopDatetime = new Dictionary<int, DateTime>();
        //获取 时间组
        public DateTime GetLoopDatetime(EDataLoopDtKey key)
        {
            if (DictLoopDatetime.TryGetValue((int)key, out var value))
            {
                return value;
            }
            else
            {
                return LoopDatetimeBase;
            }
        }
        //修改 时间组
        public DateTime SetLoopDatetime(EDataLoopDtKey key, DateTime value)
        {
            DictLoopDatetime[(int)key] = value;
            return value;
        }


    }
}